package com.it.hanzhongtravelv1.service;

import com.it.hanzhongtravelv1.dto.FoodDTO;
import com.it.hanzhongtravelv1.dto.RestaurantDTO;
import com.it.hanzhongtravelv1.entity.Food;
import com.it.hanzhongtravelv1.entity.Restaurant;
import com.it.hanzhongtravelv1.repository.FoodRepository;
import com.it.hanzhongtravelv1.repository.RestaurantRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 美食推荐服务 - 实现真实的推荐算法
 * 不使用Mock数据，基于用户偏好和美食特征进行推荐
 */
@Service
public class FoodRecommendationService {
    
    @Autowired
    private FoodRepository foodRepository;

    @Autowired
    private RestaurantRepository restaurantRepository;
    
    /**
     * 获取所有美食，并转换为DTO
     */
    public List<Food> getAllFoods() {
        return foodRepository.findAll();
    }

    /**
     * 获取所有美食名店，并转换为DTO
     */
    public List<Restaurant> getAllRestaurants() {
        return restaurantRepository.findAll();
    }

    public Food saveFood(Food food) {
        return foodRepository.save(food);
    }

    public void deleteFood(Long id) {
        foodRepository.deleteById(id);
    }

    public Restaurant saveRestaurant(Restaurant restaurant) {
        return restaurantRepository.save(restaurant);
    }

    public void deleteRestaurant(Long id) {
        restaurantRepository.deleteById(id);
    }

    private FoodDTO convertToFoodDTO(Food food) {
        FoodDTO dto = new FoodDTO();
        dto.setId(food.getId());
        dto.setName(food.getName());
        dto.setDescription(food.getDescription());
        dto.setImageUrl(food.getImageUrl());
        dto.setCategory(food.getCategory());
        dto.setSpecialFeature(food.getSpecialFeature());
        dto.setPrice(food.getPrice());
        dto.setRating(food.getRating());
        dto.setTags(food.getTags());
        return dto;
    }
    
    private RestaurantDTO convertToRestaurantDTO(Restaurant restaurant) {
        RestaurantDTO dto = new RestaurantDTO();
        dto.setId(restaurant.getId());
        dto.setName(restaurant.getName());
        dto.setAddress(restaurant.getAddress());
        dto.setRating(restaurant.getRating());
        dto.setSpecialtyDish(restaurant.getSpecialtyDish());
        dto.setAveragePrice(restaurant.getAveragePrice());
        dto.setOpeningHours(restaurant.getOpeningHours());
        dto.setPhone(restaurant.getPhone());
        return dto;
    }
} 